﻿using AspDotNet.Framework.Mvc.FirstDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AspDotNet.Framework.Mvc.FirstDemo.Controllers
{
    public class TempDataController : BaseController
    {
        public ActionResult Index1()
        {
            return View();
        }
        // GET: TempData
        [HttpPost]
        public ActionResult SetTempData(int id)
        {
            TempData[nameof(id)] = Student.Students.FirstOrDefault(p => p.ID == id);
            return RedirectToAction(nameof(Index2));
        }

        public ActionResult Index2()
        {
            /* 访问TempData中的数据后,对应的Value值将被清空 */
            return View(TempData["id"]);
        }
        public ActionResult Index3()
        {
            return View();
        }
        public ActionResult Index4(bool? IsChecked)
        {
            if (IsChecked == true)
            {
                //TempData.Keep();//保存所有的Key
                TempData.Keep("students");//保存指定的Key
            }
            return View();
        }
    }
}